<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>添加校园通知</title>
    <link href="${pageContext.request.contextPath}/css/houtaimain.css" rel="stylesheet" type="text/css" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/css/bootstrap-fileinput.css" rel="stylesheet">
</head>

<body>

<h1 class="h1_style"><i class="i_h1"></i>添加校园通告</h1>
<div class="div_left">

    <form id="form_demo"  action="${pageContext.request.contextPath}/news/updateNews" class="form_b" method="post"  enctype="multipart/form-data">

        <p class="form_p"><label class="form_label">标题：</label><input type="text" name="title" class="form_input readonly " minlength="2"  required >${news.title}<i class="i_start"></i> <a class="a_note">必填</a> </p>

        <p class="form_p"><label class="form_label">发布机构：</label><input type="text" name="authority" class="form_input readonly " minlength="2"  required >${news.authority}<i class="i_start"></i><a class="a_note">必填</a> </p>

        <p class="form_p"><label class="form_label a_area">描述：</label><textarea  name="news_txt" class="text_area1" ></textarea>${news.news_txt}</p>

        <div class="clear"></div>

</div>
<div class="container">
    <div class="page-header">
        <h3>图片上传</h3>

        <div class="form-group" id="uploadForm" enctype='multipart/form-data'>

            <div class="fileinput fileinput-new" data-provides="fileinput"  id="exampleInputUpload">
                <div class="fileinput-new thumbnail" style="width: 300px;height: auto;max-height:300px;">
                    <img id='picImg' style="width: 100%;height: auto;max-height: 100%;" src="${pageContext.request.contextPath}/${news.photo}" alt="" />
                </div>
                <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                <div>
                        <span class="btn btn-primary btn-file">
                            <span class="fileinput-new">选择文件</span>
                            <span class="fileinput-exists">换一张</span>
                            <input type="file" name="file" id="picID" accept="image/gif,image/jpeg,image/x-png"/>
                        </span>
                    <a href="javascript:;" class="btn btn-warning fileinput-exists" data-dismiss="fileinput">移除</a>
                </div>
                <p style="color: #a04121">支持jpg／jpeg/png格式图片的上传，上传图片不能大于10M</p>
            </div>
        </div>



    </div>
</div>

<div class="clear"></div>
<p class="but_p"><input type="submit" value="保存" class="but_save"/><input type="button" value="取消" class="but_close" id="close"> </p>
</form>
<script src="${pageContext.request.contextPath}/js/jquery.js"></script>

<script src="${pageContext.request.contextPath}/js/date/js/laydate.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-validation-1.14.0/dist/jquery.validate.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/js/jquery-validation-1.14.0/dist/localization/messages_zh.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap-fileinput.js"></script>
<script>
    !function () {
        laydate.skin('danlan'); //
        laydate({ elem: '#demo' });
        laydate({ elem: '#demo1' }); //
    } ();
</script>
<script >
    $.validator.setDefaults({
        submitHandler: function () {
            alert("修改成功");
        }
    });
    $().ready(function () {
        $(".form_b").validate();
    });
</script>
<script type="text/javascript">
    $(function () {
        //比较简洁，细节可自行完善
        $('#uploadSubmit').click(function () {
            var data = new FormData($('#uploadForm')[0]);
            $.ajax({
                url: 'xxx/xxx',
                type: 'POST',
                data: data,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    console.log(data);
                    if(data.status){
                        console.log('upload success');
                    }else{
                        console.log(data.message);
                    }
                },
                error: function (data) {
                    console.log(data.status);
                }
            });
        });

    })
</script>
</body>
</html>
